var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		images: {},
		pagenum: 1,
		st:''
	},
	_onLoad: function () {
		var that = this;
		this.setData({ pagenum: 1,datalist: [], $nomoreData: false })
		$.get('kanjia/index',{},function(res){
			that.setData(res)
		})
	},
	changetab: function (e) {
		var st = e.currentTarget.dataset.st
		this.setData({ pagenum: 1, st: st, datalist: [], $nomoreData: false })
		wx.pageScrollTo({
			scrollTop: 0, duration: 0
		})
		this.getDataList()
	},
	getDataList: function () {
		var that = this;
		var st = that.data.st
		var pagenum = that.data.pagenum;
		$.post('kanjia/index', { cid: st, pagenum: pagenum }, function (res) {
			var data = res.data;
			if (pagenum == 1) {
				that.setData({ datalist: data,pics:res.pics});
				if (data.length == 0) {
					$.showEmpty('没有相关数据', '/images/empty.png');
				}
			} else {
				if (data.length == 0) {
					that.setData({ $nomoreData: true });
				} else {
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
		});
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData) {
			this.setData({ pagenum: this.data.pagenum + 1 })
			this.getDataList();
		}
	},
}))
